import Vue from 'vue';
let components = {};

function registerComponent(group, component, config) {
    Vue.component(config.name, component);
    if (!components[group]) {
        components[group] = [];
    }
    components[group].push(config);
}

function getComponent(name) {
    const groups = Object.keys(components);
    let component = null;
    for (let i = 0; i < groups.length; i++) {
        const group = groups[i];
        const componentGroup = components[group];
        const componentIndex = componentGroup.findIndex(vo => vo.name === name);
        if (componentIndex >= 0) {
            component = componentGroup[componentIndex];
            break;
        }
    }
    return component;
}

function getComponentGroup(group) {
    return components[group] || [];
}

export default {
    registerComponent,
    getComponent,
    getComponentGroup,
}